package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiSysWaybillConfigEditBo;
import com.piggy.logi.sys.service.ILogiSysWaybillConfigService;
import com.piggy.logi.sys.vo.LogiSysWaybillConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 运单设置Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "运单设置控制器", tags = {"运单设置"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/waybill/config")
public class LogiSysWaybillConfigController extends BaseController {

    private final ILogiSysWaybillConfigService iLogiSysWaybillConfigService;

    /**
     * 获取运单设置
     */
    @ApiOperation("获取运单设置")
    //@SaCheckPermission("sys:waybill:config:get")
    @GetMapping("/get")
    public R<LogiSysWaybillConfigVo> getInfo() {
        Long deptId = SecurityUtils.getMainDeptId();
        return R.ok(iLogiSysWaybillConfigService.getWaybillConfig(deptId));
    }

    /**
     * 修改运单设置
     **/
    @ApiOperation("修改运单设置")
    //@SaCheckPermission("sys:waybill:config:update")
    @LogiLog(title = "运单设置", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R<Object> updateInfo(@Validated @RequestBody LogiSysWaybillConfigEditBo bo) {
        bo.setDeptId(SecurityUtils.getMainDeptId());
        iLogiSysWaybillConfigService.updateInfo(bo);
        return R.ok();
    }

}
